package com.lzb.yabbs.net;

import com.alibaba.fastjson.JSONObject;
import com.lzb.yabbs.interfaces.SendCardCallback;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.util.List;

/**
 * Created by liuzaibing on 2015/9/10.
 */
public class SendCardToNet {
    public static void sendCard(String url,List<BasicNameValuePair> pairs, final SendCardCallback sendCardCallback){
        OkHttpClientRequest.requestGet(url, pairs, new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
                sendCardCallback.fail(0);
            }

            @Override
            public void onResponse(Response response) throws IOException {
                String result=response.body().string();
                JSONObject obj=JSONObject.parseObject(result);
                if(0==obj.getInteger("code")){
                    sendCardCallback.fail(0);
                }else{
                    sendCardCallback.sucess();
                }
            }
        });
    }
}
